﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Rendering.ShaderKeywordSet
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine.Assertions;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine.Rendering
{
  /// <summary>
  ///   <para>A collection of Rendering.ShaderKeyword that represents a specific shader variant.</para>
  /// </summary>
  [NativeHeader("Editor/Src/Graphics/ShaderCompilerData.h")]
  [UsedByNativeCode]
  public struct ShaderKeywordSet
  {
    private IntPtr m_KeywordState;
    private IntPtr m_Shader;
    private IntPtr m_ComputeShader;
    private ulong m_StateIndex;

    [FreeFunction("keywords::IsKeywordEnabled")]
    private static bool IsGlobalKeywordEnabled(ShaderKeywordSet state, uint index)
    {
      return ShaderKeywordSet.IsGlobalKeywordEnabled_Injected(ref state, index);
    }

    [FreeFunction("keywords::IsKeywordEnabled")]
    private static bool IsKeywordEnabled(
      ShaderKeywordSet state,
      LocalKeywordSpace keywordSpace,
      uint index)
    {
      return ShaderKeywordSet.IsKeywordEnabled_Injected(ref state, ref keywordSpace, index);
    }

    [FreeFunction("keywords::IsKeywordEnabled")]
    private static bool IsKeywordNameEnabled(ShaderKeywordSet state, string name)
    {
      return ShaderKeywordSet.IsKeywordNameEnabled_Injected(ref state, name);
    }

    [FreeFunction("keywords::EnableKeyword")]
    private static void EnableGlobalKeyword(ShaderKeywordSet state, uint index)
    {
      ShaderKeywordSet.EnableGlobalKeyword_Injected(ref state, index);
    }

    [FreeFunction("keywords::EnableKeyword")]
    private static void EnableKeywordName(ShaderKeywordSet state, string name)
    {
      ShaderKeywordSet.EnableKeywordName_Injected(ref state, name);
    }

    [FreeFunction("keywords::DisableKeyword")]
    private static void DisableGlobalKeyword(ShaderKeywordSet state, uint index)
    {
      ShaderKeywordSet.DisableGlobalKeyword_Injected(ref state, index);
    }

    [FreeFunction("keywords::DisableKeyword")]
    private static void DisableKeywordName(ShaderKeywordSet state, string name)
    {
      ShaderKeywordSet.DisableKeywordName_Injected(ref state, name);
    }

    [FreeFunction("keywords::GetEnabledKeywords")]
    private static ShaderKeyword[] GetEnabledKeywords(ShaderKeywordSet state)
    {
      return ShaderKeywordSet.GetEnabledKeywords_Injected(ref state);
    }

    private void CheckKeywordCompatible(ShaderKeyword keyword)
    {
      if (!keyword.m_IsLocal)
        return;
      if (this.m_Shader != IntPtr.Zero)
        Assert.IsTrue(!keyword.m_IsCompute, "Trying to use a keyword that comes from a different shader.");
      else
        Assert.IsTrue(keyword.m_IsCompute, "Trying to use a keyword that comes from a different shader.");
    }

    /// <summary>
    ///   <para>Check whether a specific shader keyword is enabled.</para>
    /// </summary>
    /// <param name="keyword"></param>
    public bool IsEnabled(ShaderKeyword keyword)
    {
      this.CheckKeywordCompatible(keyword);
      return ShaderKeywordSet.IsKeywordNameEnabled(this, keyword.m_Name);
    }

    /// <summary>
    ///   <para>Check whether a specific shader keyword is enabled.</para>
    /// </summary>
    /// <param name="keyword"></param>
    public bool IsEnabled(GlobalKeyword keyword)
    {
      return ShaderKeywordSet.IsGlobalKeywordEnabled(this, keyword.m_Index);
    }

    /// <summary>
    ///   <para>Check whether a specific shader keyword is enabled.</para>
    /// </summary>
    /// <param name="keyword"></param>
    public bool IsEnabled(LocalKeyword keyword)
    {
      return ShaderKeywordSet.IsKeywordEnabled(this, keyword.m_SpaceInfo, keyword.m_Index);
    }

    /// <summary>
    ///   <para>Enable a specific shader keyword.</para>
    /// </summary>
    /// <param name="keyword"></param>
    public void Enable(ShaderKeyword keyword)
    {
      this.CheckKeywordCompatible(keyword);
      if (keyword.m_IsLocal || !keyword.IsValid())
        ShaderKeywordSet.EnableKeywordName(this, keyword.m_Name);
      else
        ShaderKeywordSet.EnableGlobalKeyword(this, keyword.m_Index);
    }

    /// <summary>
    ///   <para>Disable a specific shader keyword.</para>
    /// </summary>
    /// <param name="keyword"></param>
    public void Disable(ShaderKeyword keyword)
    {
      if (keyword.m_IsLocal || !keyword.IsValid())
        ShaderKeywordSet.DisableKeywordName(this, keyword.m_Name);
      else
        ShaderKeywordSet.DisableGlobalKeyword(this, keyword.m_Index);
    }

    /// <summary>
    ///   <para>Return an array with all the enabled keywords in the ShaderKeywordSet.</para>
    /// </summary>
    public ShaderKeyword[] GetShaderKeywords() => ShaderKeywordSet.GetEnabledKeywords(this);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool IsGlobalKeywordEnabled_Injected(
      ref ShaderKeywordSet state,
      uint index);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool IsKeywordEnabled_Injected(
      ref ShaderKeywordSet state,
      ref LocalKeywordSpace keywordSpace,
      uint index);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool IsKeywordNameEnabled_Injected(
      ref ShaderKeywordSet state,
      string name);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void EnableGlobalKeyword_Injected(ref ShaderKeywordSet state, uint index);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void EnableKeywordName_Injected(ref ShaderKeywordSet state, string name);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void DisableGlobalKeyword_Injected(ref ShaderKeywordSet state, uint index);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void DisableKeywordName_Injected(ref ShaderKeywordSet state, string name);

    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern ShaderKeyword[] GetEnabledKeywords_Injected(ref ShaderKeywordSet state);
  }
}
